<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="流程名称" prop="processName">
        <el-input v-model="queryParams.processName" placeholder="请输入流程名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="接收时间">
        <el-date-picker v-model="dateRange" style="width: 215px" size="small" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table stripe v-loading="loading" :data="todoList" :show-header="false">
      <el-table-column align="left" prop="procDefName" show-overflow-tooltip min-width="220">
        <template slot-scope="scope">
          <div class="placeholder ellipsis">{{ spliceTodoTitle(scope.row) }}</div>
          <div class="ellipsis">流程名称: {{ scope.row.procDefName }}</div>
        </template>
      </el-table-column>
      <el-table-column align="left" prop="taskName" show-overflow-tooltip min-width="160">
        <template slot-scope="scope">
          <div class="placeholder"></div>
          <div class="ellipsis">当前节点: {{ scope.row.taskName }}</div>
        </template>
      </el-table-column>
      <el-table-column align="left" prop="startUserName" show-overflow-tooltip min-width="160">
        <template slot-scope="scope">
          <div class="placeholder"></div>
          <div class="ellipsis">发起人: {{ scope.row.startUserName }}</div>
        </template>
      </el-table-column>
      <el-table-column align="left" prop="createTime" show-overflow-tooltip width="215">
        <template slot-scope="scope">
          <div class="placeholder"></div>
          <div class="ellipsis">接收时间: {{ scope.row.createTime }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <div class="placeholder"></div>
          <el-button size="mini" type="text" icon="el-icon-edit-outline" @click="handleProcess(scope.row)"
            v-hasPermi="['workflow:process:approval']">办理</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listTodoProcess } from '@/api/workflow/process';

export default {
  data () {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 流程待办任务表格数据
      todoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        processName: null,
        projectName: null,
        name: null,
        category: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created () {
    // this.getList();
  },
  methods: {
    /** 查询流程定义列表 */
    getList () {
      this.loading = true;
      listTodoProcess(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.todoList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 跳转到处理页面
    handleProcess (row) {
      this.$router.push({
        path: '/workflow/process/detail/' + row.procInsId,
        query: {
          definitionId: row.procDefId,
          deployId: row.deployId,
          taskId: row.taskId,
          finished: true,
          processed: true
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.dateRange = [];
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.title = '添加流程定义';
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download(
        'workflow/process/todoExport',
        {
          ...this.queryParams
        },
        `wf_todo_process_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>

<style lang="scss" scoped>
.placeholder {
  font-weight: bold;
  font-size: 15px;
  height: 25px;
}
</style>